package Gui.Dialogs;

import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

import Cards.Card;
import Cards.MailCardBill;
import Gui.GameFrame;
import Gui.GamePanel;
import Main.Defines;

public class MailCardBillDialog extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5576051974883456418L;

	JLabel Title;
	JLabel Cost;
	JLabel Value;

	public MailCardBillDialog(JFrame parent, final MailCardBill DrawnCard) {
		super(parent, "Mail Card Bill Dialog", true);
		setLayout(new GridLayout(0, 1, 0, 10));
		setLocationRelativeTo(parent);

		// Draws the info for DrawnCard
		Title = new JLabel("You Recieved A Mail Card Bill ");
		// Cost = new JLabel("It Costs: " + DrawnCard.getCost());
		Cost = new JLabel(DrawnCard.toString());
		// Value = new JLabel("It's Worth: " + DrawnCard.getValue());

		JButton ok = new JButton("ok");
		ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();

			}
		});

		add(Title);
		add(Cost);
		// add(Value);
		add(ok);
		pack();
		
		setVisible(true);

		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}

	public MailCardBillDialog(GameFrame parent, Vector<Card> billPile) {
		super(parent, "Mail Card Bill Dialog", true);
		setLayout(new GridLayout(0, 1, 0, 10));
		setLocationRelativeTo(parent);

		// Create the 'ok' button.
		JButton ok = new JButton("ok");
		ok.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				dispose();

			}
		});

		// Draws the info for DrawnCard
		Title = new JLabel("You Recieved Mail Card Bill(s) ");
		add(Title);

		for (Card c : billPile) {
			Cost = new JLabel(((MailCardBill) c).toString());
			add(Cost);
		}

		add(ok);
		pack();
		// REFACTOR THIS! MAGIC NUMBER
		if(getTitle() != null){
			FontMetrics fm = getFontMetrics(getFont());
			int width = fm.stringWidth(getTitle()) + 75; // MAGIC NUMBER, 75 is size of a "typical" window icon
			width = (int) Math.max(width*1.2, getPreferredSize().getWidth());
			setSize(new Dimension(width, getHeight()));
		}

		setVisible(true);

		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}
}
